package com.hello.world.http.im;

import lombok.extern.slf4j.Slf4j;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author zhaozeyang
 * @date 2018/12/3 16:37
 * @description
 */
@Slf4j
public class blackList {

    static CloseableHttpClient httpClient = HttpClientBuilder.create().build();

    static ExecutorService executorService = Executors.newFixedThreadPool(10);

    static volatile boolean stop = false;


    private final static String request = "/v1/data/articles/blacklist?article_ids=eb807850f67e9e1f13ed12b00eb21b7a,7251770c50f9db01dcdc8a22fd670ebe,56955fe4fb9ceaf4208898d0e4509df9,0b7829f3ab02eeb85e2cf2ab6da83203,104d89c9ba2fa76542f76c344dbb67f0,af6cdfdc7c269a32531defad68373cb5,bbb2310cb233b9343491106a6abb30ed,b2e49eaa5b3a7959d0d7eb2d449362bc,1a4388c3cd50aba57c0eaf1b212ffa83,12168a0a76fa46f5199f43e6a4e6e4a6,5fc89b6c4210a8c12c1e3f80bbfbbd6c,ba653fd0c388ea2affa8234543c34c48,8ca31d4a61c989cec437f0b5e353dbf3,77fa9ab0c4166128195391a42234d6cd,f78483d76c12fefd7bf142e5fab08053,81844f9825a8486eb630a2a4881be80b,dcdf61c6142e9aff9341540e82de40d1,0566308bff8d0cb797787b7c5cbf49f8,a8f982076f27d6c3bcea16bf46d68164,f0956a1b95918845910f4daf6f4f27a1,3e352f75b058595a51fbc439a49715c2,334168f479b178297636a587ccd123c7,ea181ebf309c55c815b8347c0070f833,703aa60286414a743da216d429ee035c,d3e8caaf858dfbda01e0ab2b48d89dcd,bd46e0a2d364d6a72d1f4661fc911266,3d0e9a2ef36e8baa2b9c00695a3cbbe9,30be3b6f18a8d3372c73a4515b5604ca,d5a07b909a09259ef697af863a3d9d44,b49116e3acf481070d9654bee7df4694,c21a3b94902f4829239b8e51d5de4927,d68b4a06a93971e92202c5a0b83959fc,717fb971586c611208aa1e634a17bda3,ec5c473fe47e5906b84283ac178ce6db,05e292c80d20eeef2dfbed52134538e5,8b1c9bcb2c6cef03d2a504a6029abf6d,6663817fb418c69f3d3b02468f8ebc1a,3c77e56198c7b6cd7ebe634f21e18270,e6ab15c132264328a9373b0460e83920,be3b31e4efed4d3f030388fbd29e73e3,863636afdb2ab06621dfefb3cf9d6171,8c95a09cf9a2bcfe608baab975a97506,01e1abce0a54e09966e9463d03e2f39c,adf374a4c440bce321a1c4e5c8101d15,6e72fe474a6b9217ff4dc6b3d5e65e1e,ecc402d3dda6b54803e6db4e061cf767,4e10da9605a6817aea83d17ba0537212,d637a5f240bbbee928e64a1c410c2322,7e5d26f7edf21929d298639121f48c2a,16618caa19b51f923f0be1f3cf6514f9,fbcae1c9f320f1066031b057cd8a0260,a45f0cc0d6c462f8c9502363c774ab77,d33343fef60a98329f69514f6f821dc5,cfcf3c5b080f0e04f451f66c9b1b06bb,6efef90ab6ba36e2b044c446b76be558,29f4a183e0519602e0a6f6b8ce40d89f,9d088508effbab10149fc280ae5ace70,3f583d92741bf90e4bdd06014c15fc53,e1fec546cbce1b9bfd50263b1e21f8f6,54db5a7407f9dc8895971cf0fa42295d,613e2099d051aaae33ea83a0b910c9cd,30ac8960be749e7b13db7961bb334207,e0ab304c2e644063ee923c6781010d34,0da819fa46aabb860784ac10f16e38ce,14d896c63ae28a9ab4554ff29e89a9df,93fbb3bb338c8519cbcbaf8e9872d3c7,94488ee219b671bbc1ccd6efafc1090b,65668b74ff3f6102cc9dd3421b236470,0a9c40ef7c57a8a1daed358cc25f56ae,29356776327bd595e0736f278410a8ed,ef77a96da0192810b6886ebd924fc57c,49b47e2159905c9a422b4c2fbfc31133,b909133771bcf566b2951bdac909fce8,9d05a8d69b4f25700d333ccfb06b090c,3bd3081611fb79c4ae99b9041e85cb96,11fed24fd2aebf9284626ebb1f9eb73a,c855f5381a1aa004a2eb1b09bb750228,0ba16f83fc4ee61e9860c54cd4a51a6f,21418a2b80f59900001b0c5dae988f6e,5ec34bfd394e2aee56f88722713bf702,aaa4901314d1f38d44864eda35b35ddd,525d628baf0e88b110860b156ec70713,c27a80df9ab5cd19801ac42391599e52,87f8ac4b5fa59ad28a522ed7ab21dc1e,c71b52abc0a44cb944c5080407b41eba,baf537a97a39efda63c0717ff9b40c6c,67590adc3b859f7a22077faadfd502a5,9c1861bbce40f69feb63fe65611cb61d,8d69c3896609fc5fdfe30d19b8a10422,902ee065316263d25a7c1dd659630d68,97977906cc873e2ca88754156e354a3f,962d9c7968e27708744ed9521c755828,e88e63bafe251f1c1b8571c4131d406d,f8fb7a3ad4099b681eeef18ec0d57b47,37efcb0ef5da4af618e5d278b9e5dea7,1339637b6af8ed981031fe0ec40cb511,a6170f9226aa82c35bd3aadac0e0e457,15befae296488e429f3a7d7363bfdcfc,fc50d148f76f7451102f5a516d8bbfb2,f9be421866471eb1a88e01831c7aa9c4,531d734b1ba4ea74dbce8c9959209cfe,44dfcf6a65a57feacfe1204313a6ae03,3385802372077ab8d142177774676821,25aaaf7b3277b4e72ea275d87a00d34b,d4e42f398d03ddef5133a12894f3acee,49ccb387fc4c23d9bb5dac9bf014c91f,5e86f3e4c6536b6e884f6e7ce5ea1163,8a9d561eb8624147e3959674f5c8260c,ea2f8cb22265c760b77312051d0309a5,035655904b0fb870ec5f013bfb0dbe9a,a90d1fe003a8946ad464f8809921b5d5,528b1fb2e6bf6675df95a392befdb2b0,b76e76937c398cae43b7fc0b3255d7fb,c06f88fb17a04fe74e1f024c5fe1647f,f14b8d835df16431c5d47a0b4a5e4d34,549717416bd3f84cb7fe95bdc8acd67e,68f61dbf35fa747fb0769257cd78631e,9fe2c54f32fa6ba6fa83de7227104790,dd3c7466036897d36a5b211b79693d5a,5e7ea245b6d3782f17ee3546818b0fa3,ba6dfc9c4882650c9a5940ebff44ffe4,3f148d398923610fbf446261b0fd5041,7116e3fb174e993604b95992592b3639,a1165861b4bd86904730fc606315337c,3504dae828056e0c74d1444cfa51ef25,28045c35ce760b01c0cbeb3251c57bbf,783b9899946c2985e12a00ba37e2a358,415e851c7aa2c1376bba5f378b43d317,790f9768599f2573d10d431697266945,7b16a9e04627bbdaf7cd3d518eb4ae9a,b2d33df729f0808e34bbbcf2f601ec59,ca2f22fa69802a61d05fe2933ac29cbb,d23c996c7c5e0de080a8130b2b3f3a1e,33311bbe4d2784264829c66b3b77a24d,24e20992eb409375b1a93a9513741594,fd3c126088339209cce7137c81525942,1977e65c1814b1d74784d4cec45282be,2d6bb7fce13fde8b8859fc096c884c08,839c1b585ffbfbbdcf4b67414daf96ea,bf2eb72bf6a61f895b39321c132908f3,257bb5b1c8899b9d7a2c75924ff03484,71cf3367f3907a2b0c0a34f7752f871e,109c73e129590fea5ae720a3596c9dd3,bbbc81abf16d29eced071b9faf94ab48,fbcd1d885f0237924aebda6f637d1720,f9d892ce52c6e01cf9595971537f634e,e3267c17c478ce668652ee94045c1fd5,8c1a3fe20f7d43c5bb3a8bf4807fdf1d,157bf3176e3a75431ad86f8800870256,884527b6b342c1f527235b0da75ffd47,193fbdf35e75b0ed92141869873c7005,dbac53f031cce573abad8feed94b567c,feffb5ed9b06df597fcbc84bb17d3254,406666fe78c39a62c7e753e733efe666,36bec4caa399d009a1ef30a48bc5cb11,aca8f779cada142b9f6385188ce5a2f9,5fce7c41437c281bffa001eef6c60d94,834b4850090ad4f0717c0ee444de0a2a,a135ede0fd1712ea7216af58005cf4a6,2a0f88b8aab91247edd401071b778234,e107b203ab219ca8edfd7c5340a1f2b2,326330ed939008d27728d687cbf7cc09,5ae5d0594fea3ddb5d2a15d208ee0bca,220c339d58b177ccf5f959374cc55d1f,73d592be54765f394ecce139e06498b0,a366e880b718d29834609b82363a8daf,7405c64faa71687bda7d66d2bcac2aa5,5f5ed2adeb052dda84b63c978ae2e2d8,397d8c953532818f4393492633517ce2,d1d528b5d8bf016571ae705ec475b81b,f8f5b0414ada59f9020821d862f237ce,8f0caaaede0da38df5a99399f17a1d6c,93dcc3b444fd35b53d09ee7aa7da8c2d,06743cab9e8e0c6fe0de3567b3adafe8,94cc2838b6e2d86a6a0d97d1c7fdb7d6,1657249effea1a116c62a8611be97ad7,5d625e68aa3f3bc89260f1898da9084d,2da4e2285870465ad4df76b2be0fe78f,a6f2d1ccd85efd31429eba4ed3923417,208c21470120bea53c38d694a714264a,cc744810d6ab27f667f17eccdbefb0c2,83d9c32d7b181c62615d78a2900cc5c9,28658d91b1e9ed706c5fc733f29ca7c4,f91f68eb3a979e7752214f0c5a228e04,2aa3024be8478275ed5e0503f8edb982,08e0c2e38b4021db99627c19fa980ce0,bbaf513c76816158d7d14c1342cb9fea,179594d643c7e34b331f968e5bf27310,e46fb4d0e15907a197760e83b2d02107,24427080dd967f445e3909536df43493,609261cd0ce36993f7b8a90786c68b31,21256d5110f1701ceb49562a5f235a7a,70cb7bf7203b86df087b7c60bd775f9e,a6c7c1e4837fe2b0bbbfdb6798fb6f6c,60603597bce6ae19397536e6fca5de22,5b9106014d15e96898e050849b97a99b,1945f05ad22e6eeada629837b4c80925,bfe4f5352c115d5d6c645cfaa622f831,edb6d8a797345d4b8146a70fabd9f362,9a08eb2cd0d8ac5db3632e30adf1f9f0,d57a72c5270133c95194ccac3bcbbdae,58f978a987e61c9bf9022e44eebcc0fc,021c25d8a1c86fab61fc923964af6c06,3e16370dcb39cfb71dab00d2b9821f42,4d5f503daa3fbf65766cd6ceb6c5f6f9,74f754682ae3d8a28c343da5b2d9bab3,66e0b92a323eaf62a2dca642e3b5ab17,d140f691a02614ea4a22881e9a368696,6b6c78577133addd335c79dd1a3b83fc,f30a86beec64a46c181981cd59d353db,6d75a8c2bcf5f5345389c50ab566a549,333fdda9795cdeb9d967d9da958b2a13,4f050cca463bf3e6cdeb647b354edb01,aebf494ab08da8153a5362bd17f54983,ee6efe160f2012d1574d9e500c864ede,1a9dd02480003322ab8970e637072a7a,c8d70a217804613cb033a5cfd4335460,94d1e5e922aebf2693054506d82bacc9,0dac020daff197b2a6f467a246ea86b5,517886f85815e6004eda63fc24d73306,7f6892a67304865279c21fbcd94c7a9f,e9b41d09c02b8197f0b05f6dd11316b2,764a5edc865f448729170027000e344d,e35538ee1c675076db71e058f64dcee7,5777d1c87550700e0237c77ca5f872cd,f7b1b034ee78e00d03b6fea69562af5d,f544c04e9f68321b682dc474f176f10f,09ccafaf6897bb50ee544e180252807e,2714b10b5347de06239d95f3c309eff4,48b771d2612a8c7899a85a2b9b49f941,5a73c2cbcbf46b04948db42e8d3fd3c6,70121f0dacca2edd7f7f8376b3775a9b,5a491563a31393df31a8dbf87415ba84,433fc20c0a19a197b09c01cf11b65e4e,96416900370945421ac3dae6ac370fec,a58760bc0a8e1fe9f2ae5ae4ee7c2d63,46eb366d9f7fffa4f07a9f4378153303,f7a69abff5a2662789865eafe28b84bb,b9d8c4e89f5ac6a1ed3568b5aa8c4c7e,71a234d6e004133ad3b31bbbb1df8367,c3c6979683c54345dba268a52a45963d,84895bf35e70bc0d1e70e32eb2a229da,7dab24d47ec64fbb91a224e84678b483,8df565e4977ef442b5ef0687052ae28f,9a1da21b87036be07a79a08696fbae9a,a69e14a050103f939110fd2d64f3e727,fc452805405dfe911cf39c16939d09b4,96b22beb419f9617d7fa1d2705fd29d8,1f9a910f19383b5cb6b1f761d1751bd2,db7b4d38c32719e98a0fb2822816d13f,af6d4414cc5054f6a22bb0b7c015fec1,0b85342b04e2be28872b0d9a56ea1741,f36cdd492b41303c9b3eff763739826d,d888e896a4e19445cbdb231badcbf8cb,81107d60355761936f1300d602f25b0a,b9b392a3a509d5eabf0c68b4bfe30312,ad575c415bf3ca80df94f91e4336ceb4,aedae933da045df3461d7d8f2a174820,90d1f9d7b34e5471a1212fe662ab7829,012d28ee0b818b066398873a97898d5d,6326e30cc8d96595ec1fee02e1b0a31b,f444048d7847804b5933f7bbe3d191b4,da0f28169f363eb4e8448664080cced9,ad1c7a67488c33854a12a55026802533,2f6d00031945f40af0efafa4b0733017,9af4d3e164fdcd88416d8b5e0e1b58ff,94306e262a8bea1a735222025b6d2a3d,fdf7ff3dd7a10a725c7583d8306e443f,788573afa35861175e478f5a8c2d061e,ee42cbeb9959795de9637c1ceece3a74,535da3f68d73b76fdbefe67f18041bf4,16cbc9a1a27a235f03e9355d40389ee6,afbaeaa79b38b446b72540a10e4dd466,e8ff92807a77bcce7d88821b66df031f,d405b274f78d1103940f5f128e2b380b,fcb93ee6a452f9c4e3c91c73c68a383c,1cebe0a6e851908ab7f814bc6620b229,ab969677eea03ce8dced7fa71b172fd3,e631a3f8f92551290a52318e49877bf6,3da65b99b9871c0ea2dc7df448f9356b,9493eec2ac2e23e21c2ca9febce1bfcd,fbc326e2b0eab65d3a228d7b1bd3d860,294142ead13663a28bb2770bd026b067,94fd5c8225c1b9da2d71c44cffcf6246,841f4fe21234f15912f0e3e4cd379a66,11146dd25cbd495ec9e89cf493c63e3d,8088e21ecc520a4f3db46389ee86eb23,47545f6bb0e16fd93503a03ca2c64620,163e5665d41542d990844b174a52ac70,15bb0fd14be3bd5ad9cd65c4fc559d74,e9ec26754fb869959d32f5824d4ace5e,ecf98b18fb0216d2a009586d49d100b2,300733f4b6e2022a2b98f6a414349b80,33c9c7d01b9b818f73fc731bf10cf385,ecac8cb621669169838e6d73579d9c61,4e28347165ed20ba1b6f272021b4d5b5,35c9244bccdc2e2ec4ffa9d5ec11f053,bfe8210d162b49d6f507b77bc9093778,db2d19e6cbcccc23e7c6092b91560f04,1e4eea30dd3b21edacdcfd624d41f2c7,9a7d15226efa460206de5975354909f7,a64762c4bd5548998e23703d9da609f1,6190a0989722ca116ad0d29a74ffde75,a509672a706374d3ed09c15c2d57e2df,b79b73887fc25374f6b51c88bf288a66,1f84379bd2c4ed89b93fffa36f6ae8bd,9d29afa79f78c8cd7bbcc126877b64c7,93a1f1931a17f39ad3de6ce2814ddb3d,68129b3dd13c541668955164f6ad2965,27650f5f8494332a623e23d16aa9f9d0,16c8f8621005dee3879021fa7e81fa33,05bda8921d9414e83127331f37d6450d,d7af80a10bb1d9d8260d9f7ee7c81829,41bf97e9e8b2563bc2ed18e384f6114b,8592c1b74c97c3aa6dc72cf80057c4d5,1ef6664d664944eb33932455f95fb8ea,27aef914cfaad6929212a8dcb467588e,c60bc9f9eb284c455a4ffad767938cf4,ccd2c5107ae536ada09555ce6ed133eb,2904a8bf3b38c6b138bbd118a29778f5,8d61281e7ec9c1f1de39b7456829d1a7,ad2314eb5fcbb33461ac037387eaa602,c4793cc03a7e10547e14ca240e2b1e82,ba8dd03b4dc9bf6133e495f113dd4a9e,c4f15c06439478da7892a92f295ece33,6506d6aa8329ab7ef8512722da4edc78,61a4b6f9ec0093adb9b15ea29a94ed11&lng=112.569805&v=6.6.9&distinct_id=ff808081486616630148698fc07c1dbc&client_type=2&lat=37.846829&token=ZXFEQiOUhmTPtAJ4VcQ8Wsa6dtpzh5n2A+eFNLRCORouJ/jacXex/UtviqUmPWeeNrrWEJcmHZLaPYKsMVP+hqFZF5BQ1kkm5yExO243IO0vzUn2rkxzFGA0mzk+I/ko1WPEb/8Sw/bxi1NDAzcdxlckHYlj2giyWAywCiGd99o=";
    private final static String token = "ZXFEQiOUhmTPtAJ4VcQ8Wsa6dtpzh5n2A+eFNLRCORouJ/jacXex/UtviqUmPWeeNrrWEJcmHZLaPYKsMVP+hqFZF5BQ1kkm5yExO243IO0vzUn2rkxzFGA0mzk+I/ko1WPEb/8Sw/bxi1NDAzcdxlckHYlj2giyWAywCiGd99o=";

    public static void main(String[] args) throws IOException, InterruptedException {

        new Thread(new lookStatus()).start();

        CountDownLatch countDownLatch = new CountDownLatch(3600);
        int i = 0;
        while (i < 3600) {
            for (int j = 0; j < 10; j++) {
                executorService.execute(new task(countDownLatch));
            }
            i++;
            Thread.sleep(1000);
        }
        countDownLatch.wait();
        stop = true;
    }


    static class task implements Runnable {

        private CountDownLatch countDownLatch;

        public task(CountDownLatch countDownLatch) {
            this.countDownLatch = countDownLatch;
        }

        @Override
        public void run() {
            try {
                String hots = "https://beta-xesapi.speiyou.cn";
                HttpGet httpGet = new HttpGet(hots.concat(request));
                Map<String, String> headerMap = new HashMap<String, String>() {{
                    put("Authorization", "Bearer ZXFEQiOUhmTPtAJ4VcQ8Wsa6dtpzh5n2A+eFNLRCORouJ/jacXex/UtviqUmPWeeNrrWEJcmHZLaPYKsMVP+hqFZF5BQ1kkm5yExO243IO0vzUn2rkxzFGA0mzk+I/ko1WPEb/8Sw/bxi1NDAzcdxlckHYlj2giyWAywCiGd99o=");
                    put("Content-Type", "application/json");
                }};
                headerMap.forEach(httpGet::addHeader);
                CloseableHttpResponse response = null;

                response = httpClient.execute(httpGet);

                log.info("status code is {} ----------" + response.getStatusLine().getStatusCode());

                log.info(EntityUtils.toString(response.getEntity()));
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                countDownLatch.countDown();
            }

        }
    }

    static class lookStatus implements Runnable {

        @Override
        public void run() {
            try {
                while (!stop) {
                    String ip = "172.16.25.229:8080";
                    HttpGet httpGet = new HttpGet("https://beta-xesapi.speiyou.cn/status");
                    CloseableHttpResponse response = null;
                    response = httpClient.execute(httpGet);
                    String str = EntityUtils.toString(response.getEntity());
                    String status = findStatus(str, ip);
                    log.info(status);
                    if (!status.equals("up")) {
                        log.error("-------is not up!!!,time is " + System.currentTimeMillis());
                    }
                    Thread.sleep(1000);
                }

            } catch (Exception e) {
                e.printStackTrace();
            }


        }

        private String findStatus(String str, String ip) {
            String hStr = str.replaceAll("\n", "").replaceAll(" +", "");
            int strStartIndex = hStr.indexOf(ip) + ip.length() + 9;
            int end = strStartIndex + 2;
            String result = hStr.substring(strStartIndex, end);
            return result;


        }
    }
}
